package 字符串.easy;

import java.util.*;

/**
 * @author Lw中
 * @date 2020/8/20 20:27
 */
public class YiSiLingBa {

    public static List<String> stringMatching(String[] words) {
        Set<String> stack = new HashSet<>();
        for (int i = 0; i < words.length; i++) {
            for (int j = 0; j < words.length; j++) {
                if (i != j && words[i].contains(words[j])) {
                    // stack集合存储的是无序不重复去重
                    stack.add(words[j]);
                }
            }
        }
        // 通过有参构造(在构造方法中放入set集合)创建list集合
        return new ArrayList<>(stack);
    }

    public static void main(String[] args) {
        String[] words = {"mass","as","hero","superhero"};
        List<String> strings = stringMatching(words);
        for (int i = 0; i < strings.size(); i++) {
            System.out.println(strings.get(i));
        }
    }

}
